#ifndef RPIHELITCPCLIENT_H
#define RPIHELITCPCLIENT_H
#include <QTcpSocket>
#include <QString>
#include <QDebug>
#include "ui_accelerometerWidgetUI.h"
#include "ui_compassWidgetUI.h"
#include "ui_controlsWidgetUI.h"
#include "ui_gpsWidgetUI.h"
#include "ui_gyroscopeWidgetUI.h"
#include "ui_pressureWidgetUI.h"
#include "ui_ultrasonicSensorsUI.h"
#include <QDateTime>

class rpi_sensor_compass;
class rpi_sensor_pressure;
class rpi_sensor_gps;
class rpi_sensor_acc;
class rpi_sensor_gyro;
class rpi_sensor_ultrasonic;
class rpi_control;
class rpi_imu_9dof;


class RPIHelicopterClient : public QTcpSocket
{
    Q_OBJECT
    enum RPI_FAST_MESSAGE {
        RPI_FAST_CONTROL =1
    };

    enum RPI_MESSAGES{ RPI_SERVO_STEER = 1001,RPI_SERVO_MOTOR,
                       RPI_SENSOR_ACC = 2001,
                       RPI_SENSOR_COMPASS = 3001,
                       RPI_SENSOR_GPS = 4001,
                       RPI_SENSOR_PRESSURE = 5001,
                       RPI_SENSOR_ULTRASONIC_1 =6001,
                       RPI_SENSOR_ULTRASONIC_2,
                       RPI_SENSOR_ULTRASONIC_3,
                       RPI_SENSOR_ULTRASONIC_4,
                       RPI_SENSOR_ULTRASONIC_5,
                       RPI_SENSOR_ULTRASONIC_6,
                       RPI_SENSOR_ULTRASONIC_7,
                       RPI_SENSOR_ULTRASONIC_8
                     };
public:
    explicit RPIHelicopterClient(QObject *parent = 0);
    ~RPIHelicopterClient();
    rpi_sensor_compass *compass;
    rpi_sensor_pressure *pressure;
    rpi_sensor_gps *gps;
    rpi_sensor_acc *accelerometer;
    rpi_sensor_gyro *gyroscope;
    rpi_imu_9dof *imu;
    QList <rpi_sensor_ultrasonic*> ultrasonicSensors;
    QList <rpi_control*> controls ;
    void sendXML(QString x);
signals:
    void sendAccGui(double *c);
    void updateAccelerometer();
    void updateGyroscope();
    void updateUltrasonicSensors();
    void updateGPS();
    void updatePressure();
    void updateCompass();
    void updateControls();
    void updateIMU(rpi_imu_9dof* i);

public slots:
    void saveConfig();
    void connectionMade();
    void steerTo(int i);
    void setMotorPower(int i);
    void sendInt(quint16  TYPE,quint16  value);
    void receiveData();
    void pollDevices();
    void requestControls();
    void sendControl(int k);
    void sendFastControl(int c,int v);
private:
    QDateTime zeroTime;
    double time;
};

#endif // RPIHELITCPCLIENT_H
